<template>
  <div>
    <el-table :data="ordersList">
      <el-table-column prop="pid" label="订单流水号"></el-table-column>
      <el-table-column prop="uid" label="用户id"></el-table-column>
      <el-table-column prop="commId" label="商户id"></el-table-column>
      <el-table-column prop="orderDate" label="订单创建时间"></el-table-column>
      <el-table-column label="订单状态">
        <el-tag type="warning">已付款，等待出库</el-tag>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="pageno"
      :page-sizes="[5, 10, 15, 20]"
      :page-size="pagesize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
    ></el-pagination>
    <el-button @click="submit">全部出库</el-button>
  </div>
</template>

<script>
    export default {
        name: "outboundShipment",
        data(){
          return{
            ordersList:[],
            originalData:[],//原始数据，分页前的数据
            pageno: 1,
            pagesize: 5,
            total: 1
          }
        },
        methods:{
          getData(){
            //调用异步，查询需要出库的订单
            var params = new URLSearchParams();
            params.append("pageno", this.pageno);
            params.append("pagesize", this.pagesize);
            this.$axios.get("outboundOrder.action", {params: params})
              .then(res => {
                this.ordersList = res.data.records;
                this.originalData = res.data.originalData;
                this.total = res.data.total;
                console.log(res.data);
              })
              .catch(err => {
                this.$message.error(err)
              })
          },
          handleSizeChange(val) {
            //每页范围
            this.pagesize = val;
            this.getData();
          },
          handleCurrentChange(val) {
            //当前页
            this.pageno = val;
            this.getData();
          },
          submit(){
            //检查该商户是否有要出库的订单
            if(this.originalData.length>0){
              let params = new URLSearchParams();
              //循环数组，获取所有id
              this.originalData.forEach(item=>{
                params.append("ids",item.id);
              })
              //进行异步提交，将该供应商的所有订单的数据添加到出库表和出库详情表内
              this.$axios.post("payInfo/addPayInfoandDetailPurchaseInfo.action", params)
                .then(res => {
                  if(res.data.x){
                    this.$message.success(res.data.msg);
                  }else {
                    this.$message.error(res.data.msg);
                  }
                  //重新查询一次数据
                  this.getData();
                })
                .catch(err => {
                  this.$message.error(err)
                })
            }else {
              this.$message.error("当前没有需要出库的订单");
            }
          }
        },
        created() {
          this.getData();
        }
    }
</script>

<style scoped>

</style>
